package com.lch.netty.nio.buffer;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Objects;

/**
 * IO映射缓存区
 *
 * @author: liuchenhui
 * @create: 2019-10-14 10:50
 **/
public class MappedBuffer {
    public static void main(String[] args) throws IOException {
        String path = Objects.requireNonNull(DirectBuffer.class.getClassLoader().getResource("test.txt")).getPath();
        RandomAccessFile randomAccessFile = new RandomAccessFile(path, "rw");
        FileChannel fileChannel = randomAccessFile.getChannel();

        MappedByteBuffer mappedBuffer = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, 1024);
        mappedBuffer.put(1, (byte) 97);
        randomAccessFile.close();
    }
}
